package com.my.ddd_sample_collections.association_object.south.adapter.repositories;

import com.my.ddd_sample_collections.association_object.domain.MySubscriptions;
import com.my.ddd_sample_collections.association_object.domain.Subscription;
import com.my.ddd_sample_collections.association_object.domain.User;
import com.my.ddd_sample_collections.association_object.south.adapter.clients.MySubscriptionsAPI;
import com.my.ddd_sample_collections.association_object.south.adapter.repositories.dao.UserDAO;

import java.util.List;

/**
 * @see MySubscriptionsAPI
 */
public class MySubscriptionsDB implements MySubscriptions {
    private final UserDAO userDao;
    private final User user;

    public MySubscriptionsDB(UserDAO userDAO, User user) {
        this.userDao = userDAO;
        this.user = user;
    }

    @Override
    public List<Subscription> subList(int from, int to) {
        return userDao.findSubscriptionByPage(user.getId(), from, to);
    }

    @Override
    public double getTotalSubscriptionFee() {
        return userDao.calculateSubscriptonFee(user.getId());
    }

    @Override
    public int count() {
        return userDao.countSubscription(user.getId());
    }
}
